#ifndef _OptionWin_h_
#define _OptionWin_h_

// My creation:  Allows easier cloning of window pages
#undef WINNAME
#define WINNAME EditOptionsWin

/*
  About window with some features: Remembers position, modeless so can leave open, copyable information
*/
#include "PowerWindow.h" // Contains TopWindow
#include "Config.h" // Tools for getting "Nest" of shared vars across entire project (move to project_shared.h)  Primary use is to get a list of default system directories for config files

// U++ connection
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

//============================================================================================================================
FileSel& sSD()
{
	static bool b;
	static FileSel fs;
	if(!b) {
		fs.AllFilesType();
		b = true;
	}
	return fs;
}

//============================================================================================================================
class EditOptionsWin : public WithEditOptionsLayout<PowerWindow> {

public:

	typedef EditOptionsWin CLASSNAME;

	//============================================================================================================================
	EditOptionsWin() {
		RTIMING(String().Cat() << "Creating " << QUOTEME(WINNAME));
	}

	//============================================================================================================================
	~EditOptionsWin() {
		RTIMING(String().Cat() << "Destroying " QUOTEME(WINNAME));
	}

	// SPEED: Note: Moved from constructor to open and increased  load time by about 50-100 ms (hard to measure)
	//============================================================================================================================
	void Open() {
		this->Sizeable(true).Zoomable(true);
		//PowerWindow::InitializeConfiguration(QUOTEME(WINNAME)); // Manage window position and size in an XML file in user folder
		CtrlLayout(*this);

		// Note that controls are text so that they can be user copied and selected
		fileDir.SetText("F:\\Music\\");
		fileDir.AddButton().SetMonoImage(CtrlImg::smalldown()) <<= THISBACK1(FindStdDir, &fileDir);
		fileDir.AddButton().SetMonoImage(CtrlImg::smallright()) <<= THISBACK1(FindFolder, &fileDir);
		backupDir.SetText("F:\\Music\\");
		backupDir.AddButton().SetMonoImage(CtrlImg::smalldown()) <<= THISBACK1(FindStdDir, &backupDir);
		backupDir.AddButton().SetMonoImage(CtrlImg::smallright()) <<= THISBACK1(FindFolder, &backupDir);
		
		PowerWindow::Open("editoptionswin");
	}

	//============================================================================================================================
	void Close() {
		// Serialize, mostly position information
		PowerWindow::Close("editoptionswin");  // Make sure to call PowerWindow close and not directly call TopWindow or else configuration is not saved possibly until application closes
	}

	//============================================================================================================================
	virtual void Xmlize(XmlIO xml) {
		
	}
	
	//============================================================================================================================
	void FindFolder(WithDropChoice<EditString> *fdir) {
		if(!sSD().ExecuteSelectDir()) return;
		*fdir <<= ~sSD();
	}
	
	//============================================================================================================================
	void FindSetStdDir(WithDropChoice<EditString> *fdir, String n) {
		*fdir <<= n;
	}
	
	// Find the directory of the 
	//============================================================================================================================
	void FindStdDir(WithDropChoice<EditString> *fdir) {
		String n = GetFileFolder(GetExeFilePath());
		MenuBar menu;
		if(!IsNull(n))
			menu.Add(n, THISBACK2(FindSetStdDir, fdir, n));
		Vector<String> d = GetUppDirs();
		for(int i = 0; i < d.GetCount(); i++)
			menu.Add(d[i], THISBACK2(FindSetStdDir, fdir, d[i]));
		menu.Execute(&fileDir, fileDir.GetPushScreenRect().BottomLeft());
	}
};

#endif